package com.adcc.ags.cgw.vo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Map;

/**
 * REST视图实体
 */
public class ResultVO extends BaseVO{

    // 结果状态
    private ResultState result = ResultState.SUCCESS;

    // 状态编码(0:正常,-1:服务器响应失败,-2:参数不合法,-3:MD5校验失败)
    private int code = 0;

    // 异常原因
    private String reason = "";

    // 结果集内容
    private Map<String, Object> map = new HashMap<>();

    public ResultState getResult() {
        return result;
    }

    public void setResult(ResultState result) {
        this.result = result;
    }

    public void setResult(ResultState result,int code,String reason) {
        this.result = result;
        this.code = code;
        this.reason = reason;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public void add(String key, Object value) {
        this.map.put(key, value);
    }

    @Override
    public String toJSON() throws JsonProcessingException {
        this.map.put("result", result);
        this.map.put("code",code);
        this.map.put("reason",reason);
        return new ObjectMapper().writeValueAsString(this.map);
    }
}
